enum FONT {
    //% block="ArialMT_Plain_10"
    1,
    //% block="ArialMT_Plain_16"
    2,
    //% block="ArialMT_Plain_24"
    3
}

enum RELAY {
    //% block="继电器1"
    1,
    //% block="继电器2"
    2,
}

enum SERVO {
    //% block="舵机1"
    1,
    //% block="舵机2"
    2,
}



// % color="#AA278D" iconWidth=50 iconHeight=40
namespace ESP32231001 {
/**
 **led function
**/
    //% block="LED初始化" blockType="command"
    export function led_init(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`led_init();`);

    }
    //% block="LED开" blockType="command"
    export function led_on(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`led_on();`);

    }
    //% block="LED关" blockType="command"
    export function led_off(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`led_off();`);

    }
/**
 **beep function
**/
    //% block="蜂鸣器初始化" blockType="command"
    export function beep_init(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`beep_init();`);

    }
    //% block="蜂鸣器开" blockType="command"
    export function beep_on(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`beep_on();`);

    }
    //% block="蜂鸣器关" blockType="command"
    export function beep_off(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`beep_off();`);

    }
/**
 **relay function
**/
    //% block="继电器初始化" blockType="command"
    export function relay_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`relay_init();`);
    }
    //% block="开启继电器，引脚为：[PIN]" blockType="command"
    //% PIN.shadow="dropdown" PIN.options="RELAY" PIN.defl=RELAY.1
    export function relay_on(parameter: any, block: any) {
        let PIN = parameter.PIN.code;
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`relay_on(${PIN});`);
    }
    //% block="关闭继电器，引脚为：[PIN]" blockType="command"
    //% PIN.shadow="dropdown" PIN.options="RELAY" PIN.defl=RELAY.1
    export function relay_off(parameter: any, block: any) {
        let PIN = parameter.PIN.code;
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`relay_off(${PIN});`);
    }
/**
 **servo function
**/
    //% block="舵机控制初始化，舵机引脚为：[SERVO]" blockType="command"
    //% SERVO.shadow="dropdown" SERVO.options="SERVO" 
    export function servo_init(parameter: any, block: any) {
        let SERVO = parameter.SERVO.code;
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`servo_init(${SERVO});`);
    }
    //% block="控制舵机，舵机引脚为：[SERVO]，转到角度：[Angle]" blockType="command"
    //% SERVO.shadow="dropdown" SERVO.options="SERVO" 
    //% Angle.shadow="range" Angle.params.min=0 Angle.params.max=180 Angle.defl=0
    export function servo_pos(parameter: any, block: any) {
        let SERVO = parameter.SERVO.code;
        let Angle = parameter.Angle.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`servo_pos(${SERVO},${Angle});`);
    }
/**
 **key function
**/
    //% block="按键初始化" blockType="command"
    export function key_init(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`key_init();`);

    }
    //% block="读取机械按键" blockType="reporter"
    export function key_read(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`key_read()`);

    }
    //% block="读取电容按键" blockType="reporter"
    export function key_read_touch(parameter: any, block: any) {

        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`key_read_touch()`);

    }

/**
 **dht11 function
**/
    //% block="dht11初始化" blockType="command"
    export function dht11_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`dht11_init();`);
    }
    //% block="dht11获取湿度" blockType="reporter"
    export function dht11_humidity(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`dht11_humidity()`);
    }
    //% block="dht11获取温度" blockType="reporter"
    export function dht11_temperature(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`dht11_temperature()`);
    }
/**
 **rain check function
**/
    //% block="雨水传感器初始化" blockType="command"
    export function rain_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`rain_init();`);
    }
    //% block="雨水传感器读取模拟量" blockType="reporter"
    export function rain_read_ao(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`rain_read_ao()`);
    }
    //% block="雨水传感器读取开关量" blockType="reporter"
    export function rain_read_do(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`rain_read_do()`);
    }
/**
 **fire check function
**/
    //% block="火焰传感器初始化" blockType="command"
    export function fire_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`fire_init();`);
    }
    //% block="火焰传感器读取模拟量" blockType="reporter"
    export function fire_read_ao(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`fire_read_ao()`);
    }
    //% block="火焰传感器读取开关量" blockType="reporter"
    export function fire_read_do(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`fire_read_do()`);
    }
/**
 **smog check function
**/
    //% block="烟雾传感器初始化" blockType="command"
    export function smog_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`smog_init();`);
    }
    //% block="烟雾传感器读取模拟量" blockType="reporter"
    export function smog_read_ao(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`smog_read_ao()`);
    }
    //% block="烟雾传感器读取开关量" blockType="reporter"
    export function smog_read_do(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`smog_read_do()`);
    }
/**
 **sound check function
**/
    //% block="声音传感器初始化" blockType="command"
    export function sound_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`sound_init();`);
    }
    //% block="声音传感器读取模拟量" blockType="reporter"
    export function sound_read_ao(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`sound_read_ao()`);
    }
    //% block="声音传感器读取开关量" blockType="reporter"
    export function sound_read_do(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`sound_read_do()`);
    }
/**
 **body check function
**/
    //% block="人体传感器初始化" blockType="command"
    export function body_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`body_init();`);
    }
    //% block="检测是否有人" blockType="reporter"
    export function body_read(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`body_read()`);
    }

/**
 **oled function
**/
    //% block="OLED初始化" blockType="command"
    export function oled_init(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`oled_init();`);
    }
    //% block="OLED清屏" blockType="command"
    export function oled_clear(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`oled_clear();`);
    }
    //% block="OLED开始显示" blockType="command"
    export function oled_display(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`oled_display();`);
    }
    //% block="在 x [X] y [Y]处显示 [STR] " blockType="command"
    //% STR.shadow="string" STR.defl=hello
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    export function oled_drawString(parameter: any, block: any) {
        let str = parameter.STR.code
        // str = str.slice(1,-1)
        let x = parameter.X.code
        let y = parameter.Y.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_drawString(${x}, ${y}, ${str});`);
    }
    //% block="设置字体 [FONT]" blockType="command"
    //% FONT.shadow="dropdownRound" FONT.options="FONT" FONT.defl="FONT.1"
    export function oled_setfont(parameter: any, block: any) {
        let font = parameter.FONT.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`oled_setfont(${font});`);
    }
    //% block="在 x [X] y [Y]处显示长为 [WID]，高为 [HEI]的进度条，进度条值为 [PRO]" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    //% WID.shadow="range" WID.params.min=0 WID.params.max=127 WID.defl=0
    //% HEI.shadow="range" HEI.params.min=0 HEI.params.max=63 HEI.defl=0
    //% PRO.shadow="range" PRO.params.min=0 PRO.params.max=100 PRO.defl=0
    export function oled_drawProgressBar(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        let wid = parameter.WID.code
        let hei = parameter.HEI.code
        let pro = parameter.PRO.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_drawProgressBar(${x}, ${y}, ${wid}, ${hei},${pro});`);
    }
    //% block="在 x [X] y [Y]处显示长为 [WID]，高为 [HEI]的实心矩形，进度条值为 [PRO]" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    //% WID.shadow="range" WID.params.min=0 WID.params.max=127 WID.defl=0
    //% HEI.shadow="range" HEI.params.min=0 HEI.params.max=63 HEI.defl=0
    //% PRO.shadow="range" PRO.params.min=0 PRO.params.max=100 PRO.defl=0
    export function oled_fillRect(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        let wid = parameter.WID.code
        let hei = parameter.HEI.code
        let pro = parameter.PRO.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_fillRect(${x}, ${y}, ${wid}, ${hei},${pro});`);
    }
    //% block="从 x1 [X1] y1 [Y1]到 x2 [X2] y2 [Y2]画条线" blockType="command"
    //% X1.shadow="range" X1.params.min=0 X1.params.max=127 X1.defl=0
    //% Y1.shadow="range" Y1.params.min=0 Y1.params.max=63 Y1.defl=0
    //% X2.shadow="range" X2.params.min=0 X2.params.max=127 X2.defl=0
    //% Y2.shadow="range" Y2.params.min=0 Y2.params.max=63 Y2.defl=0
    export function oled_drawLine(parameter: any, block: any) {
        let x1 = parameter.X1.code
        let y1 = parameter.Y1.code
        let x2 = parameter.X2.code
        let y2 = parameter.Y2.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_drawLine(${x1}, ${y1}, ${x2}, ${y2});`);
    }
    //% block="在 x [X] y [Y]画一个长为 [WID]，高为 [HEI]的矩形" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    //% WID.shadow="range" WID.params.min=0 WID.params.max=127 WID.defl=0
    //% HEI.shadow="range" HEI.params.min=0 HEI.params.max=63 HEI.defl=0
    export function oled_drawRect(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        let wid = parameter.WID.code
        let hei = parameter.HEI.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_fillRect(${x}, ${y}, ${wid}, ${hei});`);
    }
    //% block="在 x [X] y [Y]画一条长为 [WID]的水平线" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    //% WID.shadow="range" WID.params.min=0 WID.params.max=127 WID.defl=0
    export function oled_drawHorizontalLine(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        let wid = parameter.WID.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_drawHorizontalLine(${x}, ${y}, ${wid});`);
    }
    //% block="在 x [X] y [Y]画一个半径为 [WID]的圆" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    //% WID.shadow="range" WID.params.min=0 WID.params.max=127 WID.defl=0
    export function oled_drawCircle(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        let wid = parameter.WID.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_drawCircle(${x}, ${y}, ${wid});`);
    }
    //% block="在 x [X] y [Y]画一个半径为 [WID]的实心圆" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    //% WID.shadow="range" WID.params.min=0 WID.params.max=127 WID.defl=0
    export function oled_fillCircle(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        let wid = parameter.WID.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_fillCircle(${x}, ${y}, ${wid});`);
    }
    //% block="在 x [X] y [Y]画一个点" blockType="command"
    //% X.shadow="range" X.params.min=0 X.params.max=127 X.defl=0
    //% Y.shadow="range" Y.params.min=0 Y.params.max=63 Y.defl=0
    export function oled_setPixel(parameter: any, block: any) {
        let x = parameter.X.code
        let y = parameter.Y.code
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addSetup(`oled_init`, `oled_init();`);
        Generator.addCode(`oled_setPixel(${x}, ${y});`);
    }
    //% block="OLED反转显示" blockType="command"
    export function oled_invertDisplay(parameter: any, block: any) {
        Generator.addInclude('ycwl', '#include "ycwl.h"');
        Generator.addCode(`oled_invertDisplay();`);
    }
}
